﻿import clr
clr.AddReference('System.Web')
clr.AddReference('System.Data')

from System.Web.UI import *
from System.Web.UI.WebControls import *
from IronSharePoint import *
from Microsoft.SharePoint.WebControls import *
from System.Data import *

settings = IronSettings.Current

def OnInit(args):
	bAddButton.Click += AddTrustedLocation
	
	colMenu = SPMenuField()
	colMenu.HeaderText = "Trusted Location";
	colMenu.TextFields = "Url";
	colMenu.MenuTemplateId = "TrustedLocationListMenu";
	colMenu.NavigateUrlFields = "Url";
	colMenu.NavigateUrlFormat = "{0}";
	colMenu.TokenNameAndValueFields = "URL=Url";

	trustedLocListMenu = MenuTemplate();
	trustedLocListMenu.ID = "TrustedLocationListMenu"
	
	editMenuItem = MenuItemTemplate("Edit", "/_layouts/images/edititem.gif")
	editMenuItem.ClientOnClickNavigateUrl = "IronTrustedLocation.aspx?TrustedLocation=%URL%&Action=edit"
	trustedLocListMenu.Controls.Add(editMenuItem)
	
	deleteMenuItem = MenuItemTemplate("Delete", "/_layouts/images/delitem.gif")
	deleteMenuItem.ClientOnClickNavigateUrl = "IronTrustedLocation.aspx?TrustedLocation=%URL%&Action=delete"
	trustedLocListMenu.Controls.Add(deleteMenuItem)
	
	self.Controls.Add(trustedLocListMenu)
	gvTrustedLocations.Columns.Add(colMenu)
	
	gvTrustedLocations.DataSource = GetTable()
	gvTrustedLocations.DataBind()
	
def AddTrustedLocation(sender, args):
	self.Response.Redirect("IronTrustedLocation.aspx?Action=add")

def GetTable():
	table = DataTable()
	table.Columns.Add("Url")
	
	for link in settings.TrustedLocations:
		row = table.NewRow()
		row["Url"] = link
		table.Rows.Add(row)
		
	return table

"""
def OnLoad(args):
	settings = IronSettings.GetStore()
	
	location = SPBoundField()
	location.HeaderText = "Location"
	location.DataField = "Url"
	gvTrustedLocations.Columns.Add(location)
	
	table = DataTable()
	table.Columns.Add("Url")
	
	for link in settings.TrustedLocations:
		row = table.NewRow()
		row["Url"] = link
		table.Rows.Add(row)
		
		gvTrustedLocations.DataSource = table
		gvTrustedLocations.DataBind()
		
def AddTrustedLocation(sender, args):
	self.Response.Redirect("IronTrustedLocation.aspx")

"""
	